package com.dacd.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dacd.bean.FileListBean;
import com.dacd.pdf.R;

import java.util.List;

public class ChooseFileAdapter extends RecyclerView.Adapter<ChooseFileAdapter.ViewHolder> {

    private List<FileListBean> fileListBeans;

    public ChooseFileAdapter(List<FileListBean> fileListBeans) {
        this.fileListBeans = fileListBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = View.inflate(viewGroup.getContext(), R.layout.item_file_list, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        viewHolder.fileNameTv.setText(fileListBeans.get(i).getFileName());
        viewHolder.updateTimeTv.setText(fileListBeans.get(i).getUpdateTime());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(v, i);
            }
        });
    }

    @Override
    public int getItemCount() {
        return fileListBeans == null ? 0 : fileListBeans.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private TextView fileNameTv;
        private TextView updateTimeTv;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            fileNameTv = (TextView) itemView.findViewById(R.id.ifl_file_name_tv);
            updateTimeTv = (TextView) itemView.findViewById(R.id.ifl_file_update_time_tv);
        }
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);
    }

    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

}
